package com.sincereaddon.dao;

import com.sincereaddon.model.CameraMinute;
import com.sincereaddon.model.Passengerflow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by xjw on 2018/1/9.
 */
@Repository
public class SincereaDao {

    @Autowired
    @Qualifier("secondaryJdbcTemplate")
    private JdbcTemplate jdbcTemplatePsql;

//    public Integer insert(Passengerflow p){
//        String sql = "INSERT INTO passengerflow (id,zoneid,starttime,countenter,countexit) VALUES(?,?,?,?,?);";
//        Object[] args = {p.getId(),p.getZoneId(),p.getDateTime(),p.getCountEnter(),p.getCountExit()};
//        int resutl = jdbcTemplateMySql.update(sql,args);
//        return  resutl;
//    }

    public List<CameraMinute> getTblCountInfoCameraMinute(String cameraid,String time,int limit){
//        String sqlstr = "SELECT cameraid,innum,outnum,counttime FROM tbl_count_info_camera_minute WHERE cameraid = '%s'AND counttime >= '%s' ORDER BY counttime LIMIT %d";
        String sqlstr = "SELECT cameraid,SUM(innum) innum,SUM(outnum) outnum,counttime ,COUNT(cameraid) FROM tbl_count_info_camera_minute WHERE cameraid = '%s'AND counttime >= '%s' GROUP BY counttime,cameraid ORDER BY counttime LIMIT %d";
        String sql =String.format(sqlstr,cameraid,time,limit);
//        Object[] args = {cameraid,time,limit};
        List<CameraMinute> resutl = jdbcTemplatePsql.query(sql,new BeanPropertyRowMapper(CameraMinute.class));
        return  resutl;

    }
}
